Chapter 8\EmployeeDataIsland1.htm

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>

<XML ID=employees>
<employees>
    <employee>
        <name>
            <first>John</first>
            <last>Doe</last>
        </name>
        <position>Programmer</position>
        <phone>
            <main>(714) 555-1000</main>
        </phone>
    </employee>
    <employee>
        <name>
            <first>Jane</first>
            <last>Doe</last>
        </name>
        <position>Systems Analyst</position>
        <phone>
            <main>(714) 555-2000</main>
        </phone>
    </employee>
</employees>
</XML>

<BODY>

<H1>Employee Phone List</H1>
<HR>
<TABLE BORDER=1 WIDTH=100%>
	<TR>
		<TH>Last Name
		<TH>First Name
		<TH>Position
		<TH>Phone Number
	<TR>
<SCRIPT LANGUAGE="JavaScript">
<!--
	var xmlRoot;
	var xmlEmployee;
	var xmlName;
	var xmlPosition;
	var xmlPhone;
	var intCount;
	var intTotal;
	
	// Get the root element <employees>
	xmlRoot = employees.documentElement;
	
	// Get the total number of <employee> 
	// elements
	intTotal = xmlRoot.childNodes.length;
	
	// Iterate through all of the <employee>
	// elements and create an HTML table
	// containing their information.
	for (	intCount = 0;
			intCount < intTotal;
			intCount++ )
	{
		// Get the first employee element and 
		// assign the subsequent element 
		// objects.
		// We could have just used one 
		// JavaScript variable to point to each 				// XML object when we needed it, but 				// this makes the code more readable 
		//for now.
		xmlEmployee = xmlRoot.childNodes.item( intCount );
		xmlName = xmlEmployee.childNodes.item( 0 );
		xmlPosition = xmlEmployee.childNodes.item(1);
		xmlPhone = xmlEmployee.childNodes.item(2);
		
		// Generate the next table row and
		// first cell.
		document.write( "<TR><TD>" );
		
		// Write out the last and first names.
		document.write( xmlName.childNodes.item(1).text);
		document.write( "<TD>" );
		document.write( xmlName.childNodes.item(0).text);
		document.write( "<TD>" );
		
		// Write out the position.
		document.write( xmlPosition.text );
		document.write( "<TD>" );
		
		// Write out the Phone number.
		document.write(xmlPhone.childNodes.item(0).text);
	}
-->
</SCRIPT>

</TABLE>
</BODY>
</HTML>